﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp_MvvmCommunityTookit.ViewModels;

public partial class MainViewModel : ObservableValidator //ObservableObject
{
    private string? _value;

    public string? Value
    {
        get { return _value; }
        set
        {
            SetProperty(ref _value, value);
        }
    }

    [ObservableProperty]
    public string? _desc;

    partial void OnDescChanged(string? oldValue, string? newValue)
    {
        //throw new NotImplementedException();
    }

    [ObservableProperty]
    [Required]
    [MinLength(2)]
    [MaxLength(5)]
    [NotifyDataErrorInfo]
    public string? _age;


    public MainViewModel()
    {
        Value = "123";
        this.Desc = "黄河之水天上来";
        //this.Age = 20;

        WeakReferenceMessenger.Default.Register<string>(this, (obj, str) =>
        {

        });

        WeakReferenceMessenger.Default.Register<string, string>(this, "111", (obj, str) =>
        {

        });
    }


    [RelayCommand]
    private void DoButton(string args)
    {
        WeakReferenceMessenger.Default.Send<string>("111");

        WeakReferenceMessenger.Default.Send<string, string>("555","111");

    }


}
